<?php 
class Menu extends AppModel
{
    var $name = 'Menu';
    var $hasAndBelongsToMany =array('Producto'=>array('className'=>'Producto'));
    var $actsAs = array ('Searchable');

    function indexData() {
        $index = $this->data['Menu']['fecha'];
        return $index;
    }

    function reindexAll()
    {
        if(!$this->SearchIndex){
            $this->SearchIndex=ClassRegistry::init('SearchIndex');
        }
        
        ini_set('max_execution_time',360);
        App::import('Model', $this->name);
        $newmodel = new $this->name();
        $data=$newmodel->findAll();
        foreach($data as $i=>$row)
        {
            $newmodel->data=$row;
            $index = $newmodel->indexData();
            if($index)
            {
                    $searchEntry=$this->SearchIndex->find('first',array(
                                                    'fields'=>array(
                                                                    'id'),
                                                    'conditions'=>array(
                                                                    'model'=>$this->name,
                                                                    'association_key'=>$row[$this->name]['id'])));
                    $index_data=array(
                        'SearchIndex'=>array(
                        'model'=>$this->name,
                        'id'=>empty($searchEntry)? 0:
                        $searchEntry['SearchIndex']['id'],'association_key'=>$row[$this->name]['id'],
                        'data'=>$index));
                    $res=$this->SearchIndex->save($index_data);
            }
        }
    }
}
?>